package com.wcy.controller.user;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.wcy.entity.UserLearningHistory;
import com.wcy.entity.UserRating;
import com.wcy.entity.pageVo.ApiDescriptor;
import com.wcy.entity.pageVo.ColumnConstructor;
import com.wcy.entity.pageVo.PageData;
import com.wcy.entity.result.RatingResult;
import com.wcy.feign.user.FeignUserRatingService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
public class UserRatingController {
    @Resource
    private FeignUserRatingService feignUserRatingService;

    @GetMapping("userRating/page")
    public ResponseEntity<PageData<UserRating>> getPage(@RequestParam(name = "pageNum",defaultValue = "1") int pageNum,
                                                        @RequestParam(name = "pageSize",defaultValue = "10") int pageSize){
        return ResponseEntity.ok(new PageData<>(UserRating.class, Objects.requireNonNull(feignUserRatingService.getPage(pageNum, pageSize).getBody()),  new ApiDescriptor("userRating/add", "userRating/update", "userRating/delete"), ColumnConstructor.create()));
    }

    @GetMapping("userRating/list")
    public ResponseEntity<List<UserRating>> getList(){
        return feignUserRatingService.getList();
    }

    @PostMapping("userRating/add")
    public ResponseEntity<Void> add(@RequestBody UserRating userRating){
        return feignUserRatingService.add(userRating);
    }

    @PutMapping("userRating/update")
    public ResponseEntity<Void> update(@RequestBody UserRating userRating){
        return feignUserRatingService.update(userRating);
    }

    @DeleteMapping("userRating/delete/{id}")
    public ResponseEntity<Void> delete(@PathVariable Integer id){
        return feignUserRatingService.delete(id);
    }

    @GetMapping("userRating/resource/{id}")
    ResponseEntity<RatingResult> getByResourceId(@PathVariable("id") Integer id){
        return feignUserRatingService.getByResourceId(id);
    }

    @GetMapping("userRating/resource/{id}/hasRated")
    ResponseEntity<Boolean> getHasRated(@PathVariable("id") Integer id){
        return feignUserRatingService.getHasRated(id);
    }

    @PostMapping("userRating/resource/{id}/send")
    ResponseEntity<Boolean> sendRating(@PathVariable("id") Integer id,@RequestBody UserRating rating){
        return feignUserRatingService.sendRating(id, rating);
    }
}
